package com.tanhua.server.controller;

import com.tanhua.model.vo.QuestionnaireVO;
import com.tanhua.model.vo.ReportVo;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import com.tanhua.model.mongo.Answer;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import java.util.Map;

/**
 * 测灵魂
 */
@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;


    /**
     * 测灵魂-问卷列表
     * @return
     */
    @GetMapping
    public ResponseEntity<List<QuestionnaireVO>> testSoul() {
        List<QuestionnaireVO> list = testSoulService.testSoul();
        return ResponseEntity.ok(list);
    }

    @ApiOperation("测灵魂-提交问卷（学生实战）")
    @PostMapping
    public ResponseEntity submitTest(@RequestBody Map<String, List<Answer>> answers) {
        List<Answer> a = answers.get("answers");
        String reportId = testSoulService.submitTest(a);
        return ResponseEntity.ok(reportId);
    }

    @RequestMapping(value = "/report/{id}",method = RequestMethod.GET)
    public ResponseEntity findReportResult(@PathVariable(value = "id") String id){
        ReportVo reportVo = testSoulService.findReportResult(id);
        return ResponseEntity.ok(reportVo);
    }
}
